package com.hb.game.pk.adpter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hb.game.pk.APP;
import com.hb.game.pk.R;
import com.hb.game.pk.beans.SortNormalBean;
import com.hb.game.pk.utils.StringUtils;

public class SortNormalListAdapter extends BaseQuickAdapter<SortNormalBean.DataBeanX.DataBean, BaseViewHolder> {

    public SortNormalListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, SortNormalBean.DataBeanX.DataBean item) {
        helper.setText(R.id.tv_name, item.getNickname());
        helper.setText(R.id.tv_money, (Float.parseFloat(item.getMoneys()) / 100) + "");
        String trim = StringUtils.getString(item.getFace());
        int res = 0;
        if (StringUtils.isEmpty(trim)) {
            res = R.mipmap.ic_head_normal;
        } else {
            int i = Integer.parseInt(trim);
            res = APP.headResource.get(i - 1);
        }
        helper.setImageResource(R.id.iv_head, res);
        ImageView sortImage = (ImageView) helper.getView(R.id.iv_sort);
        TextView tvSort = (TextView) helper.getView(R.id.tv_sort);
        sortImage.setVisibility(View.GONE);
        tvSort.setVisibility(View.GONE);
        int position = helper.getPosition();
        if (position == 0) {
            sortImage.setBackgroundResource(R.mipmap.ic_sort_1);
            sortImage.setVisibility(View.VISIBLE);
        } else if (position == 1) {
            sortImage.setBackgroundResource(R.mipmap.ic_sort_2);
            sortImage.setVisibility(View.VISIBLE);
        } else if (position == 2) {
            sortImage.setBackgroundResource(R.mipmap.ic_sort_3);
            sortImage.setVisibility(View.VISIBLE);
        } else if (position > 2 && position < 9) {
            tvSort.setText("0" + (position+1));
            tvSort.setVisibility(View.VISIBLE);
        } else {
            tvSort.setText("" + (position+1));
            tvSort.setVisibility(View.VISIBLE);
        }
    }
}
